import os

from langchain_community.llms.tongyi import Tongyi
from langchain_core.output_parsers import CommaSeparatedListOutputParser
from langchain_core.prompts import PromptTemplate

os.environ["DASHSCOPE_API_KEY"] = "sk-9d8f1914800e497f8717144e860f99bc"
llm = Tongyi()

joke_query = "Tell me a joke."

parser = CommaSeparatedListOutputParser()
format_instructions = parser.get_format_instructions()

prompt = PromptTemplate(
    template="List five {subject}. \n{format_instructions}",
    input_variables=["subject"],
    partial_variables={"format_instructions": format_instructions},
)
print(parser.parse(prompt.format(subject='ice cream flavors')))

print(llm.invoke(prompt.format(subject='ice cream flavors')))
